var params = {
    pagenum: 1,
    pagesize: 10,
    cate_id: "",
    state: ''
}
var total = 0;

function renderPage() {
    layui.laypage.render({
        elem: "page",
        count: total,
        curr: params.pagenum,
        limit: params.pagesize,
        layout: ["count", "limit", "prev", "page", "next", "skip"],
        jump: function(obj, first) {
            if (first) return;
            //curr显示第几页
            //limit每页显示多少条
            params.pagenum = obj.curr
            params.pagesize = obj.limit
            getList()
        }
    })
}

function getList() {
    $.ajax({
        url: "/my/article/list",
        data: params,
        success: function(res) {
            total = res.total;
            console.log(res);
            var str = template("article-list", res)
            $("tbody").html(str)
            renderPage()
        }
    })
}
getList();
$.ajax({
        url: "/my/article/cates",
        success: function(res) {
            //动态渲染
            var str = template("selectContent", res)
            $(".cate_id").html(str);
            layui.form.render()
        }
    })
    //筛选
$(".filter").on("submit", function(e) {
        e.preventDefault()
        params.cate_id = $(".cate_id").val();
        params.state = $(".state").val();
        getList();

    })
    //删除
$("tbody").on("click", ".del", function() {
    var id = $(this).attr("data-id");
    layer.confirm("确认删除么？", {
        icon: 3,
        title: "提示"
    }, function() {
        $.ajax({
            url: "/my/article/delete/" + id,
            success: function(res) {
                layer.msg(res.message)
                getList();
            }
        })

    })
})